package com.recipedb.recipedb.repository;

import com.recipedb.recipedb.entity.Category;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CategoryRepository extends JpaRepository<Category, Long> {

    @Query("SELECT c FROM Category c JOIN RecipeCategory rc ON c.id = rc.categoryId WHERE rc.recipeId = :recipeId")
    List<Category> findByRecipeId(@Param("recipeId") Long recipeId);
}
